#!/usr/bin/env python

import sys
from os3.net.mailer import Mailer

class LiWEMailer ( object ):
	def __init__ ( self, liwe ):
		self.liwe = liwe

		self.mailer = Mailer ()
		self.mailer.set_server ( 
			smtp_server = self.liwe.cfg.get ( "smtp.server", "localhost" ),
			port 	    = self.liwe.cfg.get ( "smtp.port", 25 ),
			login       = self.liwe.cfg.get ( "smtp.login" ),
			passwd      = self.liwe.cfg.get ( "smtp.password" ),
			ssl         = self.liwe.cfg.get ( "smtp.ssl", 0 ) )

        def send ( self, sender, dest, subject = "", body = "", attach = None, cc = None, bcc = None, reply_to = "", priority = "", extra_headers = None ):
		if int ( self.liwe.cfg.get ( "smtp.debug", 0 ) ):
			fout = open ( "mail_debug.txt", "w" )
			fout.write ( 
				"""
				Sender:   %s
				Dest:     %s
				CC:	  %s
			  	BCC:	  %s
				reply_to: %s
				Subject:  %s
				Body:
				%s
				==============================================================
				""" % ( sender, dest, cc, bcc, reply_to, subject, body )
			)
			fout.close ()
		else:
			self.mailer.send ( sender, dest, subject, body, attach, cc, bcc, reply_to, priority, extra_headers )




